The present invention relates to a coding method and apparatus that codes video signals of a plurality of macroblocks and generates, from the coded video signals, video packets with a code length equal to or less than a certain value, more particularly to a coding apparatus that, when adding the video signals of the macroblock just coded would make the code length of the video packet exceed a limit value, outputs the video-signal code up to the macroblock coded previously for use as a video packet, and recodes the video signals of the macroblock just coded.
Many video-coding systems divide a picture into a large number of rectangular blocks and code each block with reference to spatially neighboring blocks in the same picture. For example, a block may be coded by predicting the content of the block from the contents of neighboring blocks that have already been coded, and coding the difference between the predicted content and the actual content. Alternatively, the motion vector of a block may be predicted and coded in this way. Motion vectors are employed when the content of a block is predicted from a block in a preceding or following picture, a process referred to as inter-coding.
For brevity, the term xe2x80x98predictxe2x80x99 will sometimes be used below to denote both predicting a value and taking the difference between the predicted value and the actual value.
In color video coding, a macroblock is a group of luminance and chrominance blocks occupying the same picture area. All blocks in the macroblock are coded in the same way, for example, by use of the same motion vector. The coded length of a macroblock, referred to below as the code length, is highly variable, depending on the content of the macroblock and how closely it can be predicted.
For transmission over communication links, coded video signals are often divided into packets, referred to herein as video packets. A video packet has a length that does not exceed a fixed limit, and includes a variable number of coded macroblocks. To reduce the propagation of errors due to lost or corrupted video packets, the macroblocks in a video packet are not coded with reference to spatially neighboring macroblocks in other video packets.
In a conventional coding system, a video packet is assembled by storing coded macroblocks one by one in a buffer until the total code length of the stored macroblocks reaches or exceeds a predetermined threshold value. If the total code length at this point is still within the video-packet limit, all of the coded macroblocks in the buffer are output as a video packet. If the total code length exceeds the video-packet limit, all but the last coded macroblock are output as a video packet, and the last macroblock is saved for inclusion in the next video packet. If the last macroblock was coded with reference to any of the macroblocks just output, however, it is coded again, this time without reference to those macroblocks, before being placed in the next video packet.
A problem in this system is that if the threshold value is set high enough to avoid wasting available video-packet space, the last macroblock will often fail to fit into the video packet, and will have to be recoded. This frequent repeated coding lowers the efficiency of the coding process.
A conventional coding system based on the MPEG-4 standard will now be described in more detail, to provide necessary background for the later description of an embodiment of the invention.
The MPEG-4 standard is a standard devised by the Moving Picture Experts Group of the ITU-T (Telecommunication Standardization Sector of the International Telecommunications Union). It was preceded by the MPEG-1 and MPEG-2 standards. The MPEG-1 standard is applied in CD-ROM, and is also used in video CD and karaoke, and in video communication over networks. The MPEG-2 standard is applied in existing television and HDTV, or in stored-media systems and communication systems.
A feature of the MPEG-4 standard that can be mentioned in contrast to the MPEG-1 and MPEG-2 standards is that it uses differing constituent elements such as objects and scenes having various characteristics, and the information of those objects and scenes is compressed and coded with variable length independently of the bit rate.
A coding apparatus based on the MPEG-4 standard and an outline of the coding will be described below.
FIG. 8 is a block diagram of a conventional coding apparatus based on the MPEG-4 standard as shown in, for example, the document xe2x80x98All about MPEG-4xe2x80x99 (Kogyo Chosakai), p. 39 to p. 40.
A video object plane (VOP), which is the basic video unit dealt with by MPEG-4, is divided into macroblocks; the video signals (luminance signal Y and color difference signals Cb and Cr) of the macroblocks are input to the coding apparatus 1 of FIG. 8, which outputs, in a bit stream, video packets including the coded video signals. The video packets output from the coding apparatus 1 are stored temporarily in a receive buffer 31 in a decoding apparatus 2, then are decoded by a decoding circuit 32.
The coding apparatus 1 comprises: a subtractor 11 to which the input video signal is input as a first input; a DCT circuit 12 that executes a direct cosine transform (DCT) on the output signal of the subtractor 11; a quantizing circuit 13 that quantizes and outputs the output signal of the DCT circuit 12; a DC/AC prediction circuit 14 that predicts the DC and AC components of the DCT coefficients of the relevant blocks in the video object plane (VOP) to which the-input macroblocks belong; a variable-length coding (VLC) circuit 15 that variable-length-codes the DCT coefficients and motion vectors (described below) of a plurality of macroblocks, divides them into video packets, then outputs them in a bit stream; a dequantizing circuit 16 that dequantizes the DCT coefficients output from the quantizing circuit 13; an inverse DCT circuit 17 that executes an inverse discrete cosine transform on the dequantized DCT coefficients; an adder 18 to which the inverse-discrete-cosine-transformed video signal is input as a first input; a memory 19 that stores the output of the adder 18; a predicted picture creation circuit 20 to which the video signal stored in the memory 19 is input as a first input and the output of a motion detection circuit 21 (described below) is input as a second input, which creates a predicted picture of the next macroblock and outputs it to the subtractor 11 and adder 18; the motion detection circuit 21 to which the video signal stored in the memory 19 is input as a first input and the video signal of a macroblock of interest is input as a second input, which detects the macroblock differing least from the macroblock of interest, outputs it to the predicted picture creation circuit 20, and outputs a motion vector, which is a signal indicating motion toward the detected macroblock, to a motion-vector prediction circuit 22 (described below); the motion-vector prediction circuit 22, which predicts motion vectors; and a control circuit 23 that controls the operation of the above circuits.
The video signals input to the coding apparatus 1 at each macroblock will now be described.
FIG. 9 is a diagram showing the video signals of the individual macroblocks input to the coding apparatus 1 of FIG. 8.
As shown in FIG. 9, a single video object plane (VOP) is divided into a plurality of macroblocks, at intervals of sixteen lines and sixteen pixels. The luminance block Y of each macroblock is further divided into sub-blocks (denoted blocks below) at intervals of eight lines and eight pixels. The color-difference blocks Cb and Cr comprise eight lines and eight pixels. When the picture format of the input video signal is 4:2:0 as in MPEG-4 version 1, the sixteen pixelsxc3x97sixteen lines of the luminance signal (Y) has the same size on the screen as the eight pixelsxc3x97eight lines of the two color-difference signals (Cb, Cr). A single macroblock accordingly comprises six blocks of eight pixelsxc3x97eight lines (8xc3x978 blocks). The VOP in FIG. 9 has a rectangular shape, and is synonymous with a frame in MPEG-2, for example.
The macroblock shown in FIG. 9 is disposed in the highest and leftmost position in the VOP. For example, if the topmost row of macroblocks in the VOP in FIG. 9 is the first row and the rest, proceeding toward the bottom, are the second row, third row, . . . , and if the leftmost column of macroblocks in the VOP in FIG. 9 is the first column, and the rest, proceeding toward the right, are the second column, third column, . . . , then the macroblock shown in FIG. 9 is the macroblock positioned in the first column and first row.
Processing in the DCT circuit 12, quantizing circuit 13, DC/AC prediction circuit 14 etc. is performed in the 8xc3x978 block units described above.
Next, the operation of the coding apparatus 1 in FIG. 8 will be described.
The video signals (luminance signal Y, color-difference signals Cb/Cr) of the macroblocks input to the coding apparatus 1 undergo a discrete cosine transform (DCT) in the DCT circuit 12 and quantization in the quantizing circuit 13 for each 8xc3x978 block. The DC component and AC components of the DCT coefficients of each quantized 8xc3x978 signal block are predicted in the DC/AC prediction circuit 14.
For intra-coding, the DC/AC prediction circuit 14 predicts the DC and AC components of the quantized DCT coefficients and passes them to the variable-length coding circuit 15; for inter-coding, it passes the quantized DCT coefficients output from the quantizing circuit 13 to the variable-length coding circuit 15 without prediction.
The detailed operation of the DC/AC prediction circuit 14 in the case of intra-coding will now be described further, with reference to the drawings.
FIG. 10 is an enlarged drawing of the 8xc3x978 luminance-signal blocks in a macroblock.
Because the DC/AC prediction circuit 14 processes 8xc3x978 blocks, the macroblock in FIG. 10 comprises 8xc3x978 luminance-signal blocks A, B, C, and X. The bottom-right 8xc3x978 block in the macroblock is the block X now being processed in the DC/AC prediction circuit 14; the bottom-left 8xc3x978 block in the macroblock in FIG. 10 is the left adjacent block A positioned to the left of the block X now being processed; the top-right 8xc3x978 block in the macroblock in FIG. 10 is the upper adjacent block C positioned adjacently above the block X now being processed; and the top-left 8xc3x978 block in the macroblock in FIG. 10 is the upper left block B.
In DC/AC prediction for intra-coding, first, the prediction direction of the DC component is determined. For example, if the quantized DCT coefficients of the block X which is now being coded are Fx(i, j) (0 xe2x89xa6ixe2x89xa67, 0xe2x89xa6jxe2x89xa67), the quantized DCT coefficients of the left adjacent block A of block X are Fa(i, j) (0xe2x89xa6ixe2x89xa67, 0xe2x89xa6jxe2x89xa67), the quantized DCT coefficients of the upper adjacent block C of block X are Fc(i, j) (0xe2x89xa6ixe2x89xa67, 0xe2x89xa6jxe2x89xa67), and the quantized DCT coefficients of the upper left block B of block X are Fb(i, j) (0xe2x89xa6ixe2x89xa67, 0xe2x89xa6jxe2x89xa67), then the prediction direction is determined from the DC component Fb(0, 0) of the quantized DCT coefficients of block B, the DC component Fa(0, 0) of the quantized DCT coefficients of block A, and the DC component Fc(0, 0) of the quantized DCT coefficients of block C.
To determine the prediction direction of the DC component, for example, if the quantization step width of the DC component of block A is Qda, the quantization step width of the DC component of block B is Qdb, and the quantization step width of the DC component of block C is Qdc, then the dequantized DC components fa(0, 0), fb(0, 0), fc(0, 0) are found from the following three equations:
fa(0, 0)=Fa(0, 0)xc3x97Qda
fb(0, 0)=Fb(0, 0)xc3x97Qdb
fc(0, 0)=Fc(0, 0)xc3x97Qdc
If the following relationship holds among these DC components fa(0, 0), fb(0, 0), fc(0, 0), then the DC component of block X is predicted from the dequantized DC component fc(0, 0) of block C.
|fa(0, 0)xe2x88x92fb(0, 0)| less than |fb(0, 0)xe2x88x92fc(0, 0)|
Conversely, if the above relationship does not hold, the DC component of block X is predicted from the dequantized DC component fa of block A.
The predicted DC component Px(0, 0) is found as follows: if predicted from of block C, the DC component is
Px(0, 0)=Fx(0, 0)xe2x88x92fc(0, 0)/Qdx
and if predicted from block A, the DC component is
xe2x80x83Px(0, 0)=Fx(0, 0)xe2x88x92fa(0, 0)/Qdx,
where Qdx is the quantization step width of the DC component of block X, and the results of the above division operations are rounded off.
Next, the AC components are predicted, using the same prediction direction as for the DC component. If the quantization parameter of block A is Qpa, the quantization parameter of block C is Qpc, the quantization parameter of block X is Qpx, and the DC component was predicted from block C, then
Px(i, 0)=Fx(i, 0)xe2x88x92(Fc(i, 0)xc3x97Qpc)/Qpx(i=1, . . . , 7)
and if the DC component was predicted from block C, then
Px(0, j)=Fx(0, j)xe2x88x92(Fa(0, j)xc3x97Qpa)/Qpx(j=1, . . . , 7)
The results of the above division operations are rounded off.
After the above AC components have been predicted independently for each block, whether or not to predict the AC components for each macroblock is determined.
For example, if prediction was performed for an arbitrary block X among the blocks constituting one macroblock on the basis of the upper adjacent block C of that block X, then a quantity SB is determined from the following Equation 1:                     SB        =                                            ∑                              i                =                1                            7                        ⁢                          "LeftBracketingBar"                              Fx                ⁡                                  (                                      i                    ,                    0                                    )                                            "RightBracketingBar"                                -                                    ∑                              i                =                1                            7                        ⁢                          "LeftBracketingBar"                              Px                ⁡                                  (                                      i                    ,                    0                                    )                                            "RightBracketingBar"                                                          (        1        )            
If prediction was performed on the basis of the left adjacent block A of block X, then SB is determined from the following Equation 2.                     SB        =                                            ∑                              j                =                1                            7                        ⁢                          "LeftBracketingBar"                              Fx                ⁡                                  (                                      0                    ,                    j                                    )                                            "RightBracketingBar"                                -                                    ∑                              j                =                1                            7                        ⁢                          "LeftBracketingBar"                              Px                ⁡                                  (                                      0                    ,                    j                                    )                                            "RightBracketingBar"                                                          (        2        )            
If the sum SBS of the SB""s of the six blocks constituting one macroblock is non-negative,
SBSxe2x89xa70
then the predictions of AC components are performed for each block as one block of the six blocks constituting one macroblock, but if SBS is less than zero, the predictions of AC components are not performed as a block in the one macroblock.
An ac_pred_flag is coded in the variable-length coding circuit 15 as additional information for each macroblock; if a prediction of AC components is performed, then ac_pred_flag=1.
For a block X belonging to a macroblock with ac_pred_flag=1, if the AC components were predicted on the basis of the upper adjacent block C of that block X, then output values Ox(i, j) are determined from the following Equation 3.                               Ox          ⁡                      (                          i              ,              j                        )                          =                  {                                                                      Px                  ⁡                                      (                                          i                      ,                      0                                        )                                                                                                (                                                            i                      =                      0                                        ,                    …                    ⁢                                          xe2x80x83                                        ,                                          7                      ;                                              j                        =                        0                                                                              )                                                                                                      Fx                  ⁡                                      (                                          i                      ,                      j                                        )                                                                                                (                                                            i                      =                      0                                        ,                    …                    ⁢                                          xe2x80x83                                        ,                                          7                      ;                                              j                        =                        1                                                              ,                    …                    ⁢                                          xe2x80x83                                        ,                    7                                    )                                                                                        (        3        )            
If the AC components were predicted on the basis of the upper adjacent block C of that block X, then the 0x(i, j) are determined from the following Equation 4:                               Ox          ⁡                      (                          i              ,              j                        )                          =                  {                                                                      Px                  ⁡                                      (                                          0                      ,                      j                                        )                                                                                                (                                                            i                      =                      0                                        ,                                          ;                                              j                        =                        0                                                              ,                    …                    ⁢                                          xe2x80x83                                        ,                    7                                    )                                                                                                      Fx                  ⁡                                      (                                          i                      ,                      j                                        )                                                                                                (                                                            i                      =                      1                                        ,                    …                    ⁢                                          xe2x80x83                                        ,                                          7                      ;                                              j                        =                        0                                                              ,                    …                    ⁢                                          xe2x80x83                                        ,                    7                                    )                                                                                        (        4        )            
For a block X belonging to a macroblock with ac_pred_flag=0, the Ox(i, j) are determined from the following Equation 5.                               Ox          ⁡                      (                          i              ,              j                        )                          =                  {                                                                      Px                  ⁡                                      (                                          0                      ,                      0                                        )                                                                                                (                                                            (                                              i                        ,                        j                                            )                                        =                                          (                                              0                        ,                        0                                            )                                                        )                                                                                                      Fx                  ⁡                                      (                                          i                      ,                      j                                        )                                                                                                (                                                            (                                              i                        ,                        j                                            )                                        ≠                                          (                                              0                        ,                        0                                            )                                                        )                                                                                        (        5        )            
The Ox(i, j) values are output to the variable-length coding circuit 15 as the output of the DC/AC prediction circuit 14.
Now in the above predictions, if the present block is on the left edge of the VOP, then because there is no left adjacent block A and no upper left block B, a predetermined constant xcex2 is used in the above predictions as the value of the dequantized DC components fa(0, 0) and fb(0, 0). In this case, the AC components Fa(i, j), Fb(i, j) ((i, j)xe2x89xa0(0, 0)) used in the above predictions are set to zero.
The median value of the range of values of the DC component of the DCT coefficients output from the DCT circuit 12, for example, is used as the above constant xcex2, so that if the DC component output from the DCT circuit 12 is an 11-bit value from 0 to 2047, then xcex2=1024.
Similarly, if the present block X is disposed at the top of the VOP, then because there is no upper adjacent block C and no upper left block B, the above constant xcex2 is used in the above predictions as the value of the dequantized DC components fc(0, 0) and fb(0, 0), and the AC components Fc(i, j), Fb(i, j) ((i, j)xe2x89xa0(0, 0)) are set to zero.
Furthermore, if the left adjacent block A of the present block X belongs to a different video packet from the present block X, the above constant xcex2 is used in the above predictions as the value of the dequantized DC component fa(0, 0) and the AC components Fa(i, j) ((i, j)xe2x89xa0(0, 0)) are-set to zero.
Similarly, if the upper adjacent block C of the present block X belongs to a different video packet from the present block X, the above constant xcex2 is used in the above predictions as the value of the dequantized DC component fc(0, 0) and the AC components Fc(i, j) ((i, j)xe2x89xa0(0, 0)) are set to zero.
Also, if the upper left block B of the present block X belongs to a different video packet from the present block X, the above constant xcex2 is used in the above predictions as the value of the dequantized DC component fb(0, 0), and the AC components Fb(i, j) ((i, j)xe2x89xa0(0, 0)) are set to zero.
With this arrangement, even if the transmitted bit stream is corrupted by an error, error propagation due to DC/AC prediction is confined to the video packet, because no reference is made in the DC/AC prediction circuit 14 to the coefficients of DC components and AC components in blocks belonging to different video packets.
The DCT coefficients of the macroblocks output from the DC/AC prediction circuit 14 are input to the variable-length coding circuit 15. The-variable-length coding circuit 15 codes the input signals, together with such additional information as quantization parameters, with variable length and outputs them in a bit stream, divided into video packets of a certain length. The above processing is termed intra-coding. A VOP in which all macroblocks are intra-coded is termed an I-VOP.
Meanwhile, the DCT coefficients output from the quantizing circuit 13 are dequantized in the dequantizing circuit 16, then decoded by an inverse discrete cosine transform in the inverse DCT circuit 17. The decoded video signals are input through the adder 18 to the memory 19. The video signals of the macroblocks stored in the memory 19 are used in inter-coding processing, which codes the difference from the video signal input to the coding apparatus 1.
When inter-coding is performed in the coding apparatus 1, the position of the video signal that differs least from the video signal of the input macroblock is detected in the motion detection circuit 21 from among the macroblocks stored in the memory 19, and a motion vector indicating the motion of the input macroblock with respect to the detected macroblock is detected. A predicted picture is created in the predicted picture creation circuit 20, based on the video signals of the macroblocks stored in the memory 19 and the motion vector detected in the motion detection circuit 21.
The vector values of the motion vectors detected in the motion detection circuit 21 are predicted in the motion- vector prediction circuit 22, and the difference from the predicted value is found.
The detailed operation of the motion-vector prediction circuit 22 will now be described, with reference to the drawings.
FIG. 11 is a diagram showing the motion vector prediction method. The macroblock now being coded is denoted MX. Macroblocks MA, MC, and MD are, respectively, the macroblocks to the left of, above, and above and to the right of the present macroblock MX.
If the motion vector of the present macroblock MX is MV=(MVx, MVy), the motion vector of macroblock MA is MV1=(MV1x, MV1y), the motion vector of macroblock MC is MV2=(MV2x, MV2y), and the motion vector of macroblock MD is MV3=(MV3x, MV3y), then the predicted value PV=(PVx, PVy) of the motion vector of macroblock MX can be found from
xe2x80x83PVx=Median(MV1x, MV2x, MV3x)
PVy=Median(MV1y, MV2y, MV3y)
where Median is a function that outputs the median value of a plurality of input values.
In the above calculation, if any one of macroblocks MA, MC, MD is outside the VOP, the calculation is performed as if the motion vector of that macroblock were (0, 0).
Moreover, if any two of macroblocks MA, MC, MD are outside the VOP, the motion vector of the remaining one macroblock in the VOP becomes the predicted value PV.
Furthermore, if macroblocks MA, MC, MD are all outside the VOP, the predicted value PV is (0, 0).
Also, in the above calculation, if any one of macroblocks MA, MC, MD belongs to a different video packet from the present macroblock MX, the calculation is performed as if the motion vector of that macroblock were (0, 0).
Moreover, if any two of macroblocks MA, MC, MD belong to a different video packet from the present macroblock MX, the motion vector of the remaining one macroblock belonging to the same video packet becomes the predicted value PV.
Furthermore, if macroblocks MA, MC, MD all belong to a different video packet from the present macroblock MX, the predicted value PV is (0, 0).
The motion-vector prediction circuit 22 outputs the difference between the motion vector MV of the present macroblock and the above predicted value PV, which is
MVxe2x88x92PV=(MVxxe2x88x92PVx, MVyxe2x88x92PVy)
to the variable-length coding circuit 15.
The predicted picture output from the predicted picture creation circuit 20 is input to the subtractor 11, and the difference signal of the video signal of the input macroblock and the predicted picture is output from the subtractor 11. DCT processing is performed on that difference signal in the DCT circuit 12, and quantization processing is performed in the quantizing circuit 13. The quantized DCT coefficients of the difference signal, together with such additional information as the motion vector predicted in the motion-vector prediction circuit 22 and the quantization parameters, are coded in the variable-length coding circuit 15. The DCT coefficients of the difference signal output from the quantizing circuit 13 are also dequantized in the dequantizing circuit 16, and inverse DCT processing is executed in the inverse DCT circuit 17 to recover the difference signal. The difference signal output from the inverse DCT circuit 17 is added in the adder 18 to the predicted picture output from the predicted picture creation circuit 20, and is stored in the memory 19.
Inter-coding includes unidirectional prediction, which creates the predicted picture only from a VOP that temporally precedes it in the display sequence of the pictures, and bidirectional prediction, which creates the predicted picture from both temporally preceding and following VOPs. A VOP coded using unidirectional prediction is termed a P-VOP; a VOP coded using bidirectional prediction is termed a B-VOP.
If the variable-length coding circuit 5 of the above coding apparatus 1 performs coding processing using, for example, a reversible variable-length code, the decoding circuit 32 in the decoding apparatus 2 may perform variable-length decoding in the reverse direction, from the end of a video packet, as well as variable-length decoding in the normal forward direction. More specifically, if a reversible variable-length code is used in the signal received by the decoding apparatus 2, and if an error occurs in variable-length decoding in-the forward direction, the decoding circuit 32 will perform variable-length decoding in the reverse direction, from the end of the video packet. In this case, it becomes necessary for the decoding apparatus 2 to store the full amount of code of the received video packet temporarily in the receive buffer 31.
The memory capacity of the receive buffer 31 in the decoding apparatus 2 is finite, however, and the memory capacity is frequently prescribed when the decoding apparatus 2 is designed or manufactured. A limit may therefore be imposed on the length (code length) of the video packets output from the variable-length coding circuit 15, so that it does not exceed the memory capacity of the receive buffer 31. Accordingly, if the variable-length coding circuit 5 uses a reversible variable-length code and the memory capacity of the receive buffer 31 is prescribed as above, it is necessary for the coding apparatus 1 to control the code length of the output video packets so that it is equal to or less than a certain length not exceeding the memory capacity of the receive buffer 31.
As a means by which the coding apparatus 1 may control the code length of the video packets, a means that judges the code length after the variable-length coding circuit 15 has sequentially coded the video signals of a plurality of macroblocks, before they have been output as a video packet, might be considered. When this means judges that the length of the video packet overruns the certain length, it will perform control so that the video-signal code of the overrunning macroblock is included in a new video packet.
As noted in FIG. 10, however, the DC/AC prediction circuit 14 determines the correlation relationships between the block X now being processed and the vertically upper block C and left adjacent block A, and if the block X now being processed is placed in a new video packet at that time, it is necessary to predict the DCT coefficients of the block X now being processed by regarding the DCT coefficients of the vertically upper block C and the DCT coefficients of the left adjacent block A as a constant (e.g., 1024). In inter-coding, also, as noted using FIG. 11, if macroblock MX is included in a new video packet, the motion-vector prediction circuit 22 must modify the predicted vector by setting the predicted value PV to (0, 0), because the left adjacent macroblock MA, the upper adjacent macroblock MC, and the upper right macroblock MD do not belong to the same video packet.
It may also happen that when the video packet changes, the code length of each block in the macroblock changes, and the code length of the overrunning blocks coded this time differs from the code length of the blocks included in the new video packet. In summary, the code of the overrunning blocks coded this time cannot be included as is in the new video packet.
Accordingly, when the video signal of the overrunning macroblock is to be included in the new video block, before coding is executed by the variable-length coding circuit 15, the video signal of the macroblock must be predicted again, using constants, in the DC/AC prediction circuit 14, and the prediction of the motion vector must be performed again in the motion-vector prediction circuit 22.
In the conventional coding apparatus 1 based on the MPEG-4 standard, however, no consideration whatsoever is given to controlling the code length of the video packets when there is a length limit on the video packets output in a bit stream from the variable-length coding circuit 15; the problem was that if the next video packet is simply generated from a judgement as to whether or not the code length is within a certain length, coding efficiency may be lowered because of the need for reprocessing of prediction and coding in regard to the video signals of the overrunning macroblock.
An object of present invention is to provide a video coding method and apparatus that can minimize the loss of coding efficiency due to limited video-packet length.
The invented coding method codes the video signals of macroblocks for output in video packets of limited length. Each macroblock is coded by use of a variable-length code, and the coded macroblocks are stored successively in a buffer. When each coded macroblock is stored in the buffer, the resulting total code length of the coded macroblocks stored in the buffer is calculated and compared with a predetermined value related to the limited video-packet length.
If the total code length exceeds the predetermined value, all but the most recently coded macroblock are output from the buffer as a video packet. The most recently coded macroblock is coded again.
If the total code length is less than the predetermined value, the code length of the next macroblock is predicted, the predicted code length is added to the total code length, and the resulting sum is compared with the predetermined value. If the sum exceeds the predetermined value, all of the coded macroblocks stored in the buffer are output as a video packet.
This scheme greatly reduces the frequency with which a macroblock has to be coded again because it will not fit into the current video packet. Coding efficiency is thereby improved.
The coding process may include the prediction of macroblock contents or motion vectors, the prediction being repeated when the coding is repeated.
The length of the most recently coded macroblock may be used as the predicted code length of the next macroblock.
Data partitioning may be used to rearrange the coded macroblock data in the video packets.
The invention also provides coding apparatus employing the invented method.